package action.cart;

import entity.User;
import service.CartService;
import service.impl.CartFactory;
import util.CookieUtil;
import action.BaseAction;

public class BuyAction extends BaseAction{
	private int bookId;
	private boolean exist;
	//injection
	private CartService cartService;
	public void setCartService(CartService cartService) {
		this.cartService = cartService;
	}
	
	public String execute() throws Exception{
		System.out.println("cartservice="+cartService);
		exist= cartService.buy(bookId);
		User user = (User)session.get("user");
		String uid = user.getId()+"";
		CookieUtil.addCookie(uid, cartService.store(), httpRes);
		return "success";
	}


	public int getBookId() {
		return bookId;
	}


	public void setBookId(int bookId) {
		this.bookId = bookId;
	}
	
	public boolean isExist() {
		return exist;
	}


	public void setExist(boolean exist) {
		this.exist = exist;
	}
	
}
